package com.sqmx.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqmx.common.annotation.Log;
import com.sqmx.common.core.controller.BaseController;
import com.sqmx.common.core.domain.AjaxResult;
import com.sqmx.common.enums.BusinessType;
import com.sqmx.system.domain.Petspecies;
import com.sqmx.system.service.IPetspeciesService;
import com.sqmx.common.utils.poi.ExcelUtil;
import com.sqmx.common.core.page.TableDataInfo;

/**
 * 宠物种类管理Controller
 * 
 * @author gzh
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/species")
public class PetspeciesController extends BaseController
{
    @Autowired
    private IPetspeciesService petspeciesService;

    /**
     * 查询宠物种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:species:list')")
    @GetMapping("/list")
    public TableDataInfo list(Petspecies petspecies)
    {
        startPage();
        List<Petspecies> list = petspeciesService.selectPetspeciesList(petspecies);
        return getDataTable(list);
    }

    /**
     * 导出宠物种类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:species:export')")
    @Log(title = "宠物种类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Petspecies petspecies)
    {
        List<Petspecies> list = petspeciesService.selectPetspeciesList(petspecies);
        ExcelUtil<Petspecies> util = new ExcelUtil<Petspecies>(Petspecies.class);
        util.exportExcel(response, list, "宠物种类管理数据");
    }

    /**
     * 获取宠物种类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:species:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(petspeciesService.selectPetspeciesById(id));
    }

    /**
     * 新增宠物种类管理
     */
    @PreAuthorize("@ss.hasPermi('system:species:add')")
    @Log(title = "宠物种类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Petspecies petspecies)
    {
        return toAjax(petspeciesService.insertPetspecies(petspecies));
    }

    /**
     * 修改宠物种类管理
     */
    @PreAuthorize("@ss.hasPermi('system:species:edit')")
    @Log(title = "宠物种类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Petspecies petspecies)
    {
        return toAjax(petspeciesService.updatePetspecies(petspecies));
    }

    /**
     * 删除宠物种类管理
     */
    @PreAuthorize("@ss.hasPermi('system:species:remove')")
    @Log(title = "宠物种类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petspeciesService.deletePetspeciesByIds(ids));
    }
}
